/**
 * @file  
  * Stores examples and provides  functionality to retrive examples one
 * at a time.
 */

#ifndef EXAMPLE_DB_H
#define EXAMPLE_DB_H

#include <vector>
#include <string>

template<typename Example, typename ExampleReader>
class ExampleDb
{
 public:
  void read_examples(ExampleReader example_reader, std::string Filename);
  Example* get_example(int example_id);
  int get_count();
  ~ExampleDb();
 private:
  std::vector<Example*> examples;
};

template<typename Example, typename ExampleReader>
  void ExampleDb<Example, ExampleReader>::read_examples(ExampleReader example_reader,
                                                       std::string Filename)
{
  example_reader(Filename, examples);
}

template<typename Example, typename ExampleReader>
  Example* ExampleDb<Example, ExampleReader>::get_example(int example_id)
{
  return examples[example_id];
}

template<typename Example, typename ExampleReader>
  int ExampleDb<Example, ExampleReader>::get_count()
{
  return examples.size();
}

template<typename Example, typename ExampleReader>
  ExampleDb<Example, ExampleReader>::~ExampleDb()
{
  for(typename std::vector<Example*>::iterator i = examples.begin();
      i != examples.end();
      i++)
    delete *i;
}

#endif // EXAMPLE_DB_H


